//
//  TGSDK.h
//  TGSDKIOS
//
//  Created by zhangmingsheng on 2024/6/12.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "TGLoginModel.h"
#import "TGUserRoleInfo.h"
#import "TGPayModel.h"
#import "TGUserPayQuery.h"

/*
 #import <TGSDKIOSFramework/TGLoginModel.h>
 #import <TGSDKIOSFramework/TGUserRoleInfo.h>
 #import <TGSDKIOSFramework/TGPayModel.h>
 #import <TGSDKIOSFramework/TGUserPayQuery.h>*/

#ifdef __cplusplus
#define TGSDK_EXTERN        extern "C" __attribute__((visibility ("default")))
#else
#define TGSDK_EXTERN        extern __attribute__((visibility ("default")))
#endif

NS_ASSUME_NONNULL_BEGIN

@protocol TGSDKDelegate <NSObject>

- (void)sdkDidLoad;
- (void)userDidLogin:(TGLoginModel *)loginModel;
- (void)userDidBind:(TGLoginModel *)loginModel;
- (void)userDidLogout;
- (void)userDidUpdateRoleInfo:(TGUserRoleInfo *)roleInfo;
- (void)userPayResult:(TGPayModel *)payModel;

@end

typedef NS_ENUM(NSUInteger, TGLoginType) {
    TGLoginTypeFastLogin = 0,
    TGLoginTypeFacebook = 1,
    TGLoginTypeGoogle,
    TGLoginTypeApple,
    TGLoginTypeGuest,
    TGLoginTypeAccount = 6
};

typedef NS_ENUM(NSUInteger, TGLoginWay) {
    TGLoginWayLogin = 0,
    TGLoginWayBind
};

@class TGUserLoginMessage;

@interface TGSDK : NSObject

@property(nonatomic, weak)id<TGSDKDelegate> delegate;

+ (instancetype)sharedInstance;

// 初始化SDK
- (void)initWithChannel:(NSString *)channel
                  appId:(NSString *)appId
                 appKey:(NSString *)appKey
             appleAppId:(NSString *)appleAppId
             policy_url:(NSString *)policy_url
          agreement_url:(NSString *)agreement_url
               ad_token:(NSString *)ad_token
                success:(nullable void (^)(void))completionHandler;

- (BOOL)application:(UIApplication*)application openURL:(NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;

// 登录
- (void)loginGuestSuccess:(void (^)(TGLoginModel *))success
                  failure:(void (^)(NSInteger, NSString *))failure;

- (void)quickLoginFromViewController:(UIViewController *)viewController
                  useGuestFirstLogin:(BOOL)useGuestFirstLogin
                             success:(nullable void (^)(TGLoginModel *loginModel))success
                             failure:(nullable void (^)(NSInteger code, NSString *message))failure;

- (void)loginFromViewController:(UIViewController *)viewController
                             success:(void (^)(TGLoginModel *))success
                             failure:(void (^)(NSInteger, NSString *))failure;

- (void)accountFromViewController:(UIViewController *)viewController
                        switchTap:(void (^)(void))switchTap
                          success:(void (^)(TGLoginModel *))success
                          failure:(void (^)(NSInteger, NSString *))failure;

- (void)logoutOnCompletionHandler:(nullable void (^)(void))completionHandler;

// 绑定
- (void)bindFromViewController:(UIViewController *)viewController
                       success:(nullable void (^)(TGLoginModel *loginModel))success
                       failure:(nullable void (^)(NSInteger code, NSString *message))failure;

// 上报用户角色信息
- (void)updateRoleInfoWithServerId:(NSString *)serverId
                   serverName:(NSString *)serverName
                       roleId:(NSString *)roleId
                     roleName:(NSString *)roleName
                    roleLevel:(NSString *)roleLevel
                      success:(nullable void (^)(TGUserRoleInfo *loginModel))success
                      failure:(nullable void (^)(NSInteger code, NSString *message))failure;

// 支付
- (void)payFromViewController:(UIViewController *)viewController
                       amount:(NSString *)amount
                     serverId:(NSString *)serverId
                      subject:(NSString *)subject
                    subjectId:(NSString *)subjectId
                       isTest:(NSInteger)isTest
                    cpOrderId:(NSString *)cpOrderId
                    extraInfo:(NSString *)extra_info
                      success:(nullable void (^)(TGPayModel *payModel))success
                      failure:(nullable void (^)(NSInteger code, NSString *message))failure;

// 支付结果查询
- (void)queryPayWithOrderId:(NSString *)orderId
              transactionId:(NSString *_Nonnull)transactionId
                     billNo:(NSString *)billNo
                    success:(nullable void (^)(TGUserPayQuery *payModel))success
                    failure:(nullable void (^)(NSInteger code, NSString *message))failure;

//删除账号
- (void)deleteAccount;

// 原生上报
- (void)adLogEventWithEventToken:(NSString *)eventToken;

- (void)firebaseLogEventWithName:(NSString *)eventName
                          values:(NSDictionary *)eventValues;


//分享
- (void)shareLinkToFacebook:(NSString *)link
         fromViewController:(UIViewController *)viewController;

- (void)saveLoginInfo:(TGUserLoginMessage *)message;

- (NSString *)getUid;
- (NSString *)getUserLoginToken;
- (NSString *)getUserLoginTime;
- (NSString *)getChannel;
- (NSString *)getAppId;
- (NSString *)getAppKey;
- (NSString *)getPolicyUrl;
- (NSString *)getAgreementUrl;
+ (NSInteger)getLastLoginType;
+ (NSInteger)getLastBindType;
- (BOOL)getUserLogout;

@end

// SDK初始化结果通知
TGSDK_EXTERN NSString* const TGSDKDidLoadEvent;
// 登录结果通知
TGSDK_EXTERN NSString* const TGSDKLoginResultEvent;
// 绑定结果通知
TGSDK_EXTERN NSString* const TGSDKBindResultEvent;
// 登出结果通知
TGSDK_EXTERN NSString* const TGSDKLogoutEvent;
// 上报角色信息结果通知
TGSDK_EXTERN NSString* const TGSDKRoleInfoResultEvent;
// 订单结果通知
TGSDK_EXTERN NSString* const TGSDKPayResultEvent;

NS_ASSUME_NONNULL_END
